package sctu.edu.java.year2016.team02.zhoujie.Day20160604.chapter10_3;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Created by ACER on 2016/6/5.
 */
/*创建Map集合创建Emp对象，并将创建的Emp对象添加到集合中
（Emp对象的id作为Map集合的键），并将id为005的对象从集合中移除。*/
public class Delete {
    public static void main(String[] args) {
Map map=new HashMap();
        Emp emp1=new Emp("001","小赵");
        Emp emp2=new Emp("002","小钱");
        Emp emp3=new Emp("003","小孙");
        Emp emp4=new Emp("004","小李");
        Emp emp5=new Emp("005","小周");
        map.put(emp1.getId(),emp1.getName());
        map.put(emp2.getId(),emp2.getName());
        map.put(emp3.getId(),emp3.getName());
        map.put(emp4.getId(),emp4.getName());
        map.put(emp5.getId(), emp5.getName());
        Set set = map.keySet();
        System.out.println("移除前：");
        Iterator it = set.iterator();
        while (it.hasNext()) {
            String id = (String) it.next();
            String name = (String) map.get(id);
            System.out.println(id + " " + name);
        }
        Iterator it1=map.keySet().iterator();
        while(it1.hasNext()){
            String key=(String)it1.next();
            if("005".equals(key)){
                it1.remove();
                map.remove(key);
            }
        }
        System.out.println("移除后:");
        Iterator it2 = set.iterator();
        while (it2.hasNext()) {
            String id = (String) it2.next();
            String name = (String) map.get(id);
            System.out.println(id + " " + name);
        }
    }
    }

